package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);


    /**
     * 新增套餐
     */
    @AutoFill(OperationType.INSERT)
    void addSetmeal(Setmeal setmeal);
    /**
     * 新增与套餐有关的菜品
     */
    void addSetmealDish(List<SetmealDish> dishes);

    /**
     * 修改套餐状态
     */
    @Update("update setmeal set status = #{status} where id = #{id}")
    void updateStatus(Integer id, Integer status);

    /**
     * 根据id查询套餐信息
     */
    @Select("select * from setmeal where id = #{id}")
    SetmealVO getSetmealById(Integer id);

    @Select("select name from category where id = #{categoryId}")
    String getCateGoryName(Long categoryId);

    @Select("select * from setmeal_dish where setmeal_id = #{id}")
    List<SetmealDish> getSetmealDishes(Integer id);

    /**
     * 分页查询套餐
     */
    List<SetmealVO> page(String name, Integer status, Integer categoryId);

    void deleteSetmeal(List<Integer> ids);

    /**
     * 动态条件查询套餐
     * @param setmeal
     * @return
     */
    List<Setmeal> list(Setmeal setmeal);

    /**
     * 根据套餐id查询菜品选项
     * @param setmealId
     * @return
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);

    // 更新套餐信息
    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);
}
